const $api = require('./../../utils/request').API;
Component({
  /**
   * 组件的属性列表
   */
  lifetimes:{
    attached: function() {
      console.log('进去组件projuectlist')
      this.getProjectTypeList();  // H获取项目分类
      this.getProjectList();
    },
  },
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    loading:true,
    dataList:[],
    option1: [
      { text: '全部', value: '' },
    ],
    option2: [
      { text: '默认排序', value: '' },

    ],
    value1: '',
    value2: '',
    params:{
      tProjectTypeIdFk:'',
      needJiShiStatusChk:1
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getProjectTypeList(){
        $api.getProjectTypeList().then(res=>{
          res.list.forEach(element => {
            this.data.option1.push( { text: element.projectTypeName, value:  element.id },)  
          })
          this.setData({ option1: this.data.option1})
        })
      },

      getProjectList(type){
        wx.showLoading({
          title: '正在加载',
        });
        $api.getProjectList(this.data.params).then(res=>{
        wx.hideLoading();
          this.setData({
            dataList:res.page.list
          })
        })
      },
      goDetail(e){
        let detail = JSON.stringify(e.currentTarget.dataset.item)
            wx.navigateTo({
      url: `../goodsDetail/goodsDetail?detail=${encodeURIComponent(detail)}`
    })
      },


      onSwitch1Change({ detail }){
        var objName = 'params.tProjectTypeIdFk'
        this.setData({
          [objName]:detail
        })
        this.getProjectList();
      },
      onSwitch2Change({ detail }){
        console.log(detail);
      }
  },


})
